<?php
class TextPassword {
	static $V  = array("a", "e", "i", "o", "u", "y");
    static $VN = array("a", "e", "i", "o", "u", "y","2","3","4","5","6","7","8","9");
    static $C  = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z");
    static $CN = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z","2","3","4","5","6","7","8","9");
	
	protected $_word = '';
	protected $_useNumber = true;
	protected $_wordlen = 8;
	
	public function __construct() {
	}
	public function getWordlen() {
		return $this->_wordlen;
	}
	
	public function setWordlen($wordlen)
    {
        $this->_wordlen = $wordlen;
        return $this;
    }
    
    public function getWord()
    {
        return $this->_word;
    }

    protected function _setWord($word)
    {
        $this->_word   = $word;
        return $this;
    }
    
    protected function _generateWord()
    {
        $word       = '';
        $wordLen    = $this->getWordLen();
        $vowels     = $this->_useNumbers ? self::$VN : self::$V;
        $consonants = $this->_useNumbers ? self::$CN : self::$C;

        for ($i=0; $i < $wordLen; $i = $i + 2) {

            $consonant = $consonants[array_rand($consonants)];
            $vowel     = $vowels[array_rand($vowels)];
            $word     .= $consonant . $vowel;
        }

        if (strlen($word) > $wordLen) {
            $word = substr($word, 0, $wordLen);
        }

        return $word;
    }
    
    public function generate()
    {
        $word = $this->_generateWord();
        $this->_setWord($word);
        return $word;
    }
    
}
?>